home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tegl6b.zip / INTROPAK.EXE / lha / MENUDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1991-06-26  |  16KB  |  394 lines

  1. {-----------------------------------------------------------------------------}
  2. {               TEGL Windows ToolKit II                  }
  3. {          Copyright (C) 1990, TEGL Systems Corporation              }
  4. {                All Rights Reserved.                  }
  5. {-----------------------------------------------------------------------------}
  6. {$M 16384, 64000, 655000 }
  7.  
  8. {$I switches.inc}
  9.  
  10. USES
  11.     Dos,
  12.     crt,
  13.     errorlog,
  14.     TGraph,
  15.     {$IFNDEF TEGLDEMO}
  16.     teglfnt2,
  17.     {$ENDIF}
  18.     TeglFont,
  19.     FastGrph,
  20.     TEGLIntr,
  21.     TEGLMenu,
  22.     TEGLUnit,
  23.     virtmem,
  24.     teglmain;
  25.  
  26.  
  27. const
  28.     BeepTimes  : word = 3;
  29.     DropClick  : word = 0;
  30.     DropClick1 : boolean = TRUE;
  31.     DropClick2 : boolean = FALSE;
  32.     DropClick3 : boolean = FALSE;
  33.  
  34.  
  35. { This event provides the standard exit. }
  36. {$F+}
  37. Function ExitOption(fs:ImageStkPtr; ms: MsClickPtr) : Word;
  38. {$F-}
  39.    BEGIN
  40.       AbortExit('Menu keys test');
  41.    END;
  42.  
  43. { This event is only added by the AddEntry event. When clicked on, this
  44.   event drops its own option menu entry from the menu.}
  45. {$F+}
  46. Function DeleteEntry(fs:ImageStkPtr; ms: MsClickPtr) : Word;
  47. {$F-}
  48.    var OM : optionmptr;
  49.    begin
  50.       {returns the related Option Menu chain}
  51.       OM := GetFSOM(fs);
  52.  
  53.       {Drops the current option entry, using the
  54.        ms^.clicknumber as the entry number}
  55.       DropOptionEntry(OM,ms^.clicknumber);
  56.  
  57.       deleteEntry := 1;
  58.    end;
  59.  
  60. { AddEntries demonstrates how you can retrieve the current Option Menu and
  61.   its related Option entry and insert another option entry into the current
  62.   option menu.}
  63. {$F+}
  64. Function AddEntries(fs:ImageStkPtr; ms: MsClickPtr) : Word;
  65. {$F-}
  66.    var OM : optionmptr;
  67.    begin
  68.       {returns the related Option Menu chain}
  69.       OM := GetFSOM(fs);
  70.  
  71.       {sets the Option entry position in preparation of inserting another
  72.        entry. If the option entry number is 0, DefineOptions will create
  73.        an entry at the beginning of the chain. }
  74.       SetCurrentOEPos(OM,ms^.clicknumber-1);
  75.  
  76.       {use the standard DefineOptions()
  77.             DefineOptionsRadio()
  78.             DefineOptionsCheck()
  79.              or DefineOptionsSub()
  80.        to create a new entry}
  81.  
  82.       DefineOptions(OM,'~D~elete Entry ',TRUE,deleteentry);
  83.       AddEntries := 1;
  84.    end;
  85.  
  86.  
  87. { You can change the action of the menu bar to drop down menus in which the
  88.   menu drops with a passing of the mouse. "dropclick" is an automatic variable
  89.   which is by the menu routines before calling this event. The value in the
  90.   "dropclick" is either 0 or 1 as passed by the DefineOptionsRadio() below. }
  91.  
  92. {$F+}
  93. Function DropClickToggle(fs:ImageStkPtr; ms: MsClickPtr) : Word;
  94. {$F-}
  95.    begin
  96.       {resets the complete mouseclick chain stored in a FS to MSClick or
  97.        MSSense. MSClick is a boolean value of 0, and MSSense is 1.}
  98.       ResetMSClickSense(fs^.relatedstack,boolean(dropclick));
  99.  
  100.       DropClickToggle := 1;
  101.    end;
  102.  
  103.  
  104. { Acknowledge is a simple event that aknowledges that it has been called
  105.   by beeping. The number of beeps is controlled by the variable Beeptimes;
  106.   which is an automatic variable updated by the menu routines. For more
  107.   info on automatic variables, look at the menu defines for DefineOptionsRadio(). }
  108.  
  109. {$F+}
  110. Function Acknowledge(fs:ImageStkPtr; ms: MsClickPtr) : Word;
  111. {$F-}
  112.    var i : word;
  113.    BEGIN
  114.       {Use WaitforUserRelease to wait for the user to release either the key
  115.        or mouse button before proceeding. Waiting for the user to release the
  116.        mouse button is not necessary in a menu since the menu waits for you
  117.        to release before calling the event. However if you use the same event
  118.        for icons or other defined mouse click areas, this event may be
  119.        called several times before the button is release.}
  120.  
  121.       WaitForUserRelease;
  122.  
  123.       for i:=1 to BeepTimes do
  124.      begin
  125.         Beep(1000,1,150);
  126.         Beep(500,1,50);
  127.      end;
  128.       Acknowledge := 1;
  129.    END;
  130.  
  131.  
  132. { Defining the option menus may be defined within a procedure or at the
  133.   MAIN part of the program. }
  134.  
  135. procedure CreateMenuBarEvents;
  136.    VAR    om1,om2,om3,om4,om5,om6 : optionmptr;
  137.    begin
  138.       {StandardFont is set with the initialization of TEGL in Fastgrph.
  139.        When creating Option menus, the proportional flag is saved with
  140.        each option menu, therefore if you wish to have non-proportional
  141.        menus, you must set the proportional flag off before creating
  142.        the option menu.}
  143.  
  144.       setproportional(True);
  145.  
  146.       {OM1 is a standard menu with each entry attached to the Acknowledge event.
  147.        The dashed line is used to indicate a line separator between topics.}
  148.       {$IFNDEF TEGLDEMO}
  149.       standardfont := @ROMAN25;
  150.       {$ELSE}
  151.       standardfont := @font14;
  152.       {$ENDIF}
  153.  
  154.       OM1 := CreateOptionMenu(standardfont);
  155.       DefineOptions(OM1,'DeskTop Info...',TRUE,Acknowledge);
  156.       DefineOptions(OM1,'--',FALSE,nilunitproc);
  157.       DefineOptions(OM1,'Calculator',TRUE,Acknowledge);
  158.       DefineOptions(OM1,'Clock',TRUE,Acknowledge);
  159.       DefineOptions(OM1,'Snapshot',TRUE,Acknowledge);
  160.  
  161.  
  162.       {OM2 uses a combination of several features offered in TEGLMENU.
  163.        The first is the ">" symbol in Open. This symbol tells the option
  164.        menu (when listing) to right justify the remaining portion of the
  165.        text.
  166.  
  167.        The curly brackets around F1^ will display F1^ in tiny font.
  168.  
  169.        The tilde ~ character indicates the underscoring of the enclosed
  170.        characters, of which the first character becomes the default keyboard
  171.        activator.
  172.  
  173.        Global key clicks like Alt-x and ctrl-F1 must be defined using the
  174.        definelocal and defineglobal key clicks. The menu routine only
  175.        recognizes alphabets and numeric characters when attaching
  176.        local key clicks. }
  177.  
  178.       SetMenuMargin(0);
  179.       OM2 := CreateOptionMenu(standardfont);
  180.       DefineOptions(OM2,'Open >{ctrl-F1}',TRUE,Acknowledge);
  181.       DefineOptions(OM2,'Show ~I~nfo...',FALSE,Acknowledge);
  182.       DefineOptions(OM2,'--',FALSE,nilunitproc);
  183.       DefineOptions(OM2,'~N~ew Folder...',FALSE,Acknowledge);
  184.       DefineOptions(OM2,'~C~lose',FALSE,Acknowledge);
  185.       DefineOptions(OM2,'Close ~W~indow',FALSE,Acknowledge);
  186.       DefineOptions(OM2,'--',FALSE,nilunitproc);
  187.       DefineOptions(OM2,'~F~ormat...',TRUE,Acknowledge);
  188.       DefineOptions(OM2,'To ~O~utput',TRUE,Acknowledge);
  189.       DefineOptions(OM2,'{ALT-X}~Q~uit',TRUE,exitoption);
  190.       DefineGlobalKeyClickArea(NIL,NIL,$082d,false,exitoption);
  191.       DefineGlobalKeyClickArea(NIL,NIL,$003b,false,Acknowledge);
  192. {     setommaxwidth(om2,50); }
  193.  
  194.       { DefineOptionsRadio provides a method of toggling between options or
  195.     group of options. The controlling variable is updated automatically
  196.     by the menu handler before the your event is called. You can use
  197.     "Nilunitproc" if you don't need any other activity after the user
  198.     has toggle the appropriate menu choices.
  199.  
  200.     The parameters 1,2,3,4 in DefineOptionsRadio is the value that is used
  201.     to compare against the variable BeepTimes in determing whether or not
  202.     the entry is prefixed with a check mark. When defining radio
  203.     entries, be sure to set the menu margins to 10 or more pixels to
  204.     allow room for the check mark symbol.}
  205.  
  206.       SetMenuMargin(10);
  207.       OM3 := CreateOptionMenu(standardfont);
  208.       DefineOptionsRadio(OM3,'~C~lick Menus',TRUE,DropClickToggle,0,DropClick);
  209.       DefineOptionsRadio(OM3,'~D~rop Menus',TRUE,DropClickToggle,1,DropClick);
  210.  
  211.       DefineOptions(OM3,'-',FALSE,nilunitproc);
  212.       DefineOptionsCheck(OM3,'~A~-Toggle',TRUE,nilunitproc,DropClick1);
  213.       DefineOptionsCheck(OM3,'~B~-Toggle',TRUE,nilunitproc,DropClick2);
  214.       DefineOptionsCheck(OM3,'~C~-Toggle',TRUE,nilunitproc,DropClick3);
  215.  
  216.       DefineOptions(OM3,'-',FALSE,nilunitproc);
  217.       DefineOptionsCheck(OM3,'~S~ound On',TRUE,Acknowledge,BeepStatus);
  218.       DefineOptions(OM3,'-',FALSE,nilunitproc);
  219.       DefineOptionsRadio(OM3,'Beep ~1~ time ',TRUE,Acknowledge,1,BeepTimes);
  220.       DefineOptionsRadio(OM3,'Beep ~2~ times',TRUE,Acknowledge,2,BeepTimes);
  221.       DefineOptionsRadio(OM3,'Beep ~3~ times',FALSE,Acknowledge,3,BeepTimes);
  222.